package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2024/9/20 09:28
 * @apiNote 111
 */

public class Test01493LongestSubarray {

    public int longestSubarray(int[] nums) {
        int l = 0;
        int res = 0;
        boolean has = false;
        for(int i = 0;i<nums.length;i++) {
            while(has && nums[i] == 0){
                if(nums[l] == 0){
                    has = false;
                }
                l++;
            }
            if(nums[i] == 0){
                has = true;
            }
            res = Math.max(res, i-l);
        }
        return res;
    }


}
